package com.library.service.student;

import com.library.dao.BorrowrecDao;
import com.library.dao.PayrecDao;
import java.util.List;

public class FineService {
    private BorrowrecDao borrowrecDao = new BorrowrecDao();
    private PayrecDao payrecDao = new PayrecDao();

    // 查询罚款
    public List<Object[]> getFineList(String sno, String fineStatus) {
        return borrowrecDao.getFineList(sno, fineStatus);
    }

    // 交罚款
    public String payFine(String serNum, String sno) {
        List<Object[]> fineList = borrowrecDao.getFineList(sno, "未缴");
        double totalFine = 0;
        for (Object[] fine : fineList) {
            if (fine[5] instanceof java.math.BigDecimal) {
                totalFine += ((java.math.BigDecimal) fine[5]).doubleValue();
            } else if (fine[5] instanceof Number) {
                totalFine += ((Number) fine[5]).doubleValue();
            }
        }
        if (totalFine == 0) {
            return "未找到对应未缴罚款记录！";
        }
        int paySerNum = payrecDao.insertPayrec(sno, totalFine);
        if (paySerNum == 0) {
            return "交款失败，系统异常！";
        }
        return borrowrecDao.payFine(serNum, sno, totalFine);
    }
} 